package OfferCode;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @Author Kechelle
 * @Date 2020/9/11 16:21
 * @Version 1.0
 */
public class Code18 {
    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) return null;
        //如果是头结点相等
        if (head.val == val) return head.next;
        //定义指针寻找等于val的前一个节点
        ListNode node = head;
        while (node.next != null && node.next.val != val){
            node = node.next;
        }
        node.next = node.next.next;
        return head;
    }
}
